home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / XAMPP 1.4.14 / xampp-win32-1.4.14-installer.exe / xampp / php / pear / docs / XML_fo2pdf / README.fo2pdf next >
Text File  |  2004-03-24  |  4KB  |  96 lines

  1.  fo to pdf converter.
  2.  
  3.  with fo (formating objects) it's quite easy to convert xml-documents into
  4.   pdf-docs (and not only pdf, but also ps, pcl, txt and more)
  5.  
  6.  An introduction into formating objects can be found at
  7.   http://www.w3.org/TR/xsl/slice6.html#fo-section
  8.   http://www.ibiblio.org/xml/books/bible/updates/15.html
  9.  A tutorial is here:
  10.   http://www.xml.com/pub/a/2001/01/17/xsl-fo/
  11.   http://www.xml.com/pub/a/2001/01/24/xsl-fo/
  12.  A html_to_fo.xsl can also be found there
  13.   http://www.xml.com/2001/01/24/xsl-fo/fop_article.tgz
  14.   but it didn't work for my simple xhtml files..
  15.  
  16.  The way to use this class is, produce a fo-file from a xml-file with a
  17.  xsl-stylesheet, then feed this class with this fo-file and you get a pdf
  18.  back (either directly to the browser for really dynamic-pdf production or
  19.  as a file on your filesystem)
  20.  
  21.  It is recommended to use the Cache-Classes from PEAR, if you want dynamic
  22.  pdf production, since the process of making the pdfs takes some time. For
  23.  an example of how to  use Cache and fo2pdf see below.
  24.  
  25.  Requirements:
  26.  
  27. - You need Fop (version 0.20.1 was used for testing) from the xml-apache 
  28.    project (http://xml.apache.org/fop) and Java (1.1.x or later, i tested 
  29.    it with 1.2.2 from sun on linux, see the Fop-Docs for details).
  30.    
  31. - Furthermore you have to compile your php with --with-java and to adjust
  32.    your php.ini file. It can be a rather painful task to get java and php
  33.    to work together. (i also tested this only with jdk 1.2.2, got 1.3.1 to work
  34.    but not together with sablotron....)
  35.    See http://www.phpbuilder.com/columns/marknold20001221.php3 or
  36.    http://www.linuxwebdevnews.com/articles/php-java-xslt.php?pid=347 or
  37.    http://www.onlamp.com/pub/a/php/2001/06/14/php_jav.html or
  38.    http://php.chregu.tv/java-debian.html (some config tips)
  39.    for more details about java and php.
  40.    For your reference, my relevant parts in php.ini looks like this:
  41.    ***
  42.    extension=libphp_java.so
  43.    extension.dir=/usr/local/lib/php/20010901/
  44.    [java]
  45.     java.class.path=/usr/local/lib/php/php_java.jar:/usr/local/share/java/fop.jar:/usr/local/share/java/batik.jar:/usr/share/java/xalan-2.0.1.jar:/usr/share/java/xerces.jar:/usr/local/share/java/jimi-1.0.jar
  46.    java.library=/usr/lib/java/jre/lib/i386/libjava.so
  47.    ***
  48.  
  49.  
  50. - If you want to include images or svg-files, then FOP needs an XServer (this is a
  51.     limitation of the graphics-support in java. See 
  52.     http://www.geocities.com/marcoschmidt.geo/java-image-coding.html
  53.     for details). Normally webservers don't have Xservers installed, but I made 
  54.     some good experiences with Xfvb.
  55.  
  56.  Usage:
  57.     require_once("XML/fo2pdf.php");
  58.     //make a pdf from simple.fo and save the pdf in a tmp-folder
  59.     $fop = new xml_fo2pdf();
  60.     // the following 2 lines are the default settins, so not
  61.     // necessary here, but you can set it to other values        
  62.     $fop->setRenderer("pdf");
  63.     $fop->setContentType("application/pdf");
  64.     //If you want other fonts in your PDF, you need to declare them in a
  65.     // config file. Declare here the path to this file [optional]. 
  66.     // More information about fonts and fop on the apache-fop webpage.
  67.     $fop->setConfigFile("userconfig.xml");    
  68.      if (PEAR::isError($error = $fop->run("simple.fo")))
  69.      {
  70.       die("FOP ERROR: ". $error->getMessage());
  71.      }
  72.     //print pdf to the outputbuffer,
  73.     // including correct Header ("Content-type: application/pdf")
  74.     $fop->printPDF();
  75.     //delete the temporary pdf file
  76.     $fop->deletePDF();
  77.  
  78.    With Cache:
  79.     require_once("XML/fo2pdf.php");
  80.     require_once("Cache/Output.php");
  81.     $container = "file";
  82.     $options = array("cache_dir"=>"/tmp/");
  83.     $cache = new Cache_Output("$container",$options);
  84.     $cache_handle = $cache->generateID($REQUEST_URI);
  85.     if ($content = $cache->start($cache_handle)) {
  86.       Header("Content-type: application/pdf");
  87.       print $content;
  88.       die();
  89.     }
  90.     $fop = new xml_fo2pdf();
  91.     $fop->run("simple.fo");
  92.     $fop->printPDF();
  93.     $fop->deletePDF();
  94.     print $cache->end("+30");
  95.  
  96.